﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace AgLux
{
    /// <summary>
    /// //
    /// </summary>
    /// 
    public class Course : Canvas
    {
        private string _title, _description;
        private Tree _sectionTree;

        private Navigator _navigator;
        private Introduction _introduction;
        private Summary _summary;

        /// <summary>
        /// //
        /// </summary>

        /// <param name="title">
        /// //
        /// </param>

        /// <param name="description">
        /// //
        /// </param>

        /// <param name="sectionTree">
        /// //
        /// </param>

        public Course(string title, string description, Tree sectionTree)
            : base()
        {
            _title = title;
            _description = description;
            _sectionTree = sectionTree;

            _navigator = new Navigator(_sectionTree);
            _introduction = new Introduction(_title, _description);
            _summary = new Summary(_title, _description);

            _introduction.Leave += new EventHandler(introduction_Leave);
            _summary.Leave += new EventHandler(summary_Leave);

            _navigator.LeaveForIntroduction += new EventHandler(navigator_LeaveForIntroduction);
            _navigator.LeaveForSummary += new EventHandler(navigator_LeaveForSummary);

            Children.Add(_introduction);

            //Children.Add(new Print(_sectionTree.PrintOut(true)));
            //Children.Add(new Print(_sectionTree.PrintOut(false)));
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void introduction_Leave(object sender, EventArgs args)
        {
            _navigator.LoadSection(_sectionTree.FirstSection());

            Children.Clear();
            Children.Add(_navigator);
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void summary_Leave(object sender, EventArgs args)
        {
            _navigator.LoadSection(_sectionTree.FirstSection());

            Children.Clear();
            Children.Add(_navigator);
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void navigator_LeaveForIntroduction(object sender, EventArgs args)
        {
            Children.Clear();
            Children.Add(_introduction);
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void navigator_LeaveForSummary(object sender, EventArgs args)
        {
            Children.Clear();
            Children.Add(_summary);
        }
    }
}
